
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using Spinning.Spinning.Unitity;
using Microsoft.Xna.Framework;
using Microsoft.Xna.Framework.Graphics;
using Microsoft.Devices.Sensors;

namespace Spinning.Spinning.Entity
{
    public abstract class Scene : BaseEntity
    {
       protected Texture2D _backTexture;
        public TouchManager TouchManager { get; protected set; }
        public Camera Camera{get;protected set;}

        public Scene()
            : base()
        {
            Size = new Vector2(1);
            TouchManager = new TouchManager(this);
            Camera = new Camera();
        }

        public Vector2 Size { get; set; }

        public override void OnLoad()
        {
            _backTexture = new Texture2D(Game1.graphicsDevice, 1, 1);
            _backTexture.SetData(new[] { Color.White });
        }

        protected override void UpdateSelf(GameTime gameTime)
        {
            base.UpdateSelf(gameTime);
            TouchManager.OnUpdate(gameTime);
        }

        protected override void UpdateProjection(GameTime gameTime)
        {
            Matrix m = Camera.Projection;//screen

            if (Parent != null)
            {
                m = Parent.GetProjectionMatrix();
            }
            Projection = m;
        }

        public override void OnDraw(Microsoft.Xna.Framework.Graphics.SpriteBatch spriteBatch, Microsoft.Xna.Framework.GameTime gameTime)
        {
            spriteBatch.Begin(SpriteSortMode.Immediate, BlendState.AlphaBlend, SamplerState.LinearClamp, DepthStencilState.None, RasterizerState.CullCounterClockwise, null, Projection);
            spriteBatch.Draw(_backTexture, Position, null, this.Color, Rotation, Origin, Scale * Size, SpriteEffects.None, 0);
            spriteBatch.End();
            drawChildren(spriteBatch, gameTime);
        }

        public abstract Scene Clone();
    }
}
